package cn.ggsaas.security.handler;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 登录过期/未登录  handler
 *
 * @author xuhongliang
 * @date 2020/5/25
 */
public class LoginExpireHandler implements AuthenticationEntryPoint {

	@Override
	public void commence(HttpServletRequest request, HttpServletResponse response,
						 AuthenticationException authException) throws IOException, ServletException {
		response.setContentType("application/json; charset=utf-8");
		response.getWriter().write("{\"code\": 401, \"msg\": \"登录过期或未登录\"}");
	}
}
